{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 5.2 案例实战：员工离职预测模型搭建"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**5.2.1 模型搭建**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1.数据读取与预处理\n",
    "\n",
    "首先读取员工信息以及其交易离职表现，即是否离职记录，代码如下："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>工资</th>\n",
       "      <th>满意度</th>\n",
       "      <th>考核得分</th>\n",
       "      <th>工程数量</th>\n",
       "      <th>月工时</th>\n",
       "      <th>工龄</th>\n",
       "      <th>离职</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>低</td>\n",
       "      <td>3.8</td>\n",
       "      <td>0.53</td>\n",
       "      <td>2</td>\n",
       "      <td>157</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>中</td>\n",
       "      <td>8.0</td>\n",
       "      <td>0.86</td>\n",
       "      <td>5</td>\n",
       "      <td>262</td>\n",
       "      <td>6</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>中</td>\n",
       "      <td>1.1</td>\n",
       "      <td>0.88</td>\n",
       "      <td>7</td>\n",
       "      <td>272</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>低</td>\n",
       "      <td>7.2</td>\n",
       "      <td>0.87</td>\n",
       "      <td>5</td>\n",
       "      <td>223</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>低</td>\n",
       "      <td>3.7</td>\n",
       "      <td>0.52</td>\n",
       "      <td>2</td>\n",
       "      <td>159</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  工资  满意度  考核得分  工程数量  月工时  工龄  离职\n",
       "0  低  3.8  0.53     2  157   3   1\n",
       "1  中  8.0  0.86     5  262   6   1\n",
       "2  中  1.1  0.88     7  272   4   1\n",
       "3  低  7.2  0.87     5  223   5   1\n",
       "4  低  3.7  0.52     2  159   3   1"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "df = pd.read_excel('员工离职预测模型.xlsx')\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "处理文本内容，代码如下："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>工资</th>\n",
       "      <th>满意度</th>\n",
       "      <th>考核得分</th>\n",
       "      <th>工程数量</th>\n",
       "      <th>月工时</th>\n",
       "      <th>工龄</th>\n",
       "      <th>离职</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>3.8</td>\n",
       "      <td>0.53</td>\n",
       "      <td>2</td>\n",
       "      <td>157</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>8.0</td>\n",
       "      <td>0.86</td>\n",
       "      <td>5</td>\n",
       "      <td>262</td>\n",
       "      <td>6</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>1.1</td>\n",
       "      <td>0.88</td>\n",
       "      <td>7</td>\n",
       "      <td>272</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "      <td>7.2</td>\n",
       "      <td>0.87</td>\n",
       "      <td>5</td>\n",
       "      <td>223</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>3.7</td>\n",
       "      <td>0.52</td>\n",
       "      <td>2</td>\n",
       "      <td>159</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   工资  满意度  考核得分  工程数量  月工时  工龄  离职\n",
       "0   0  3.8  0.53     2  157   3   1\n",
       "1   1  8.0  0.86     5  262   6   1\n",
       "2   1  1.1  0.88     7  272   4   1\n",
       "3   0  7.2  0.87     5  223   5   1\n",
       "4   0  3.7  0.52     2  159   3   1"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = df.replace({'工资': {'低': 0, '中': 1, '高': 2}})\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2.提取特征变量和目标变量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "X = df.drop(columns='离职') \n",
    "y = df['离职']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3.划分训练集和测试集"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.model_selection import train_test_split\n",
    "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=123)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4.模型训练及搭建"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DecisionTreeClassifier(ccp_alpha=0.0, class_weight=None, criterion='gini',\n",
       "                       max_depth=3, max_features=None, max_leaf_nodes=None,\n",
       "                       min_impurity_decrease=0.0, min_impurity_split=None,\n",
       "                       min_samples_leaf=1, min_samples_split=2,\n",
       "                       min_weight_fraction_leaf=0.0, presort='deprecated',\n",
       "                       random_state=123, splitter='best')"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.tree import DecisionTreeClassifier\n",
    "model = DecisionTreeClassifier(max_depth=3, random_state=123) \n",
    "model.fit(X_train, y_train)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "上述模型搭建代码汇总"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DecisionTreeClassifier(ccp_alpha=0.0, class_weight=None, criterion='gini',\n",
       "                       max_depth=3, max_features=None, max_leaf_nodes=None,\n",
       "                       min_impurity_decrease=0.0, min_impurity_split=None,\n",
       "                       min_samples_leaf=1, min_samples_split=2,\n",
       "                       min_weight_fraction_leaf=0.0, presort='deprecated',\n",
       "                       random_state=123, splitter='best')"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1.读取数据与简单预处理\n",
    "import pandas as pd\n",
    "df = pd.read_excel('员工离职预测模型.xlsx')\n",
    "df = df.replace({'工资': {'低': 0, '中': 1, '高': 2}})\n",
    "\n",
    "# 2.提取特征变量和目标变量\n",
    "X = df.drop(columns='离职') \n",
    "y = df['离职']   \n",
    "\n",
    "# 3.划分训练集和测试集\n",
    "from sklearn.model_selection import train_test_split\n",
    "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=123)\n",
    "\n",
    "# 4.模型训练及搭建\n",
    "from sklearn.tree import DecisionTreeClassifier\n",
    "model = DecisionTreeClassifier(max_depth=3, random_state=123)\n",
    "model.fit(X_train, y_train)    "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**5.2.2 模型预测及评估**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**1.直接预测是否离职**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 1 1 0 1 0 1 0 0 1 0\n",
      " 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 0 1 0 1 1 0 0 0 0 0 0 0 0 0\n",
      " 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 1 1 1 0 0 0]\n"
     ]
    }
   ],
   "source": [
    "y_pred = model.predict(X_test)\n",
    "print(y_pred[0:100])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>预测值</th>\n",
       "      <th>实际值</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   预测值  实际值\n",
       "0    0    0\n",
       "1    0    0\n",
       "2    1    1\n",
       "3    0    0\n",
       "4    0    0"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 通过构造DataFrame进行对比\n",
    "a = pd.DataFrame()  # 创建一个空DataFrame \n",
    "a['预测值'] = list(y_pred)\n",
    "a['实际值'] = list(y_test)\n",
    "a.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.9573333333333334\n"
     ]
    }
   ],
   "source": [
    "# 如果要查看整体的预测准确度，可以采用如下代码：\n",
    "from sklearn.metrics import accuracy_score\n",
    "score = accuracy_score(y_pred, y_test)\n",
    "print(score)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.9573333333333334"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 或者用模型自带的score函数查看预测准确度\n",
    "model.score(X_test, y_test)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**2.预测不离职&离职概率**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "其实分类决策树模型本质预测的并不是准确的0或1的分类，而是预测其属于某一分类的概率，可以通过如下代码查看预测属于各个分类的概率："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0.98526077 0.01473923]\n",
      " [0.98526077 0.01473923]\n",
      " [0.28600613 0.71399387]\n",
      " [0.98526077 0.01473923]\n",
      " [0.92283214 0.07716786]]\n"
     ]
    }
   ],
   "source": [
    "y_pred_proba = model.predict_proba(X_test)\n",
    "print(y_pred_proba[0:5])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>不离职概率</th>\n",
       "      <th>离职概率</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.985261</td>\n",
       "      <td>0.014739</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.985261</td>\n",
       "      <td>0.014739</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.286006</td>\n",
       "      <td>0.713994</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.985261</td>\n",
       "      <td>0.014739</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.922832</td>\n",
       "      <td>0.077168</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      不离职概率      离职概率\n",
       "0  0.985261  0.014739\n",
       "1  0.985261  0.014739\n",
       "2  0.286006  0.713994\n",
       "3  0.985261  0.014739\n",
       "4  0.922832  0.077168"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b = pd.DataFrame(y_pred_proba, columns=['不离职概率', '离职概率']) \n",
    "b.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "如果想查看离职概率，即查看y_pred_proba的第二列，可以采用如下代码，这个是二维数组选取列的方法，其中逗号前的“:”表示所有行，逗号后面的数字1则表示第二列，如果把数字1改成数字0，则提取第一列不离职概率。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.01473923, 0.01473923, 0.71399387, ..., 0.01473923, 0.94594595,\n",
       "       0.01473923])"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_pred_proba[:,1]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**3.模型预测效果评估**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "在Python实现上，通过4.3节讲过的代码就可以求出在不同阈值下的命中率（TPR）以及假警报率（FPR）的值，从而可以绘制ROC曲线。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.metrics import roc_curve\n",
    "fpr, tpr, thres = roc_curve(y_test, y_pred_proba[:,1])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "通过4.3节相关代码可以查看不同阈值下的假警报率和命中率，代码如下："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>阈值</th>\n",
       "      <th>假警报率</th>\n",
       "      <th>命中率</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.247110</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.945946</td>\n",
       "      <td>0.008232</td>\n",
       "      <td>0.677746</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.713994</td>\n",
       "      <td>0.038128</td>\n",
       "      <td>0.942197</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.077168</td>\n",
       "      <td>0.159879</td>\n",
       "      <td>0.969653</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0.059406</td>\n",
       "      <td>0.171577</td>\n",
       "      <td>0.972543</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>0.045763</td>\n",
       "      <td>0.240035</td>\n",
       "      <td>0.976879</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>0.014739</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         阈值      假警报率       命中率\n",
       "0  2.000000  0.000000  0.000000\n",
       "1  1.000000  0.000000  0.247110\n",
       "2  0.945946  0.008232  0.677746\n",
       "3  0.713994  0.038128  0.942197\n",
       "4  0.077168  0.159879  0.969653\n",
       "5  0.059406  0.171577  0.972543\n",
       "6  0.045763  0.240035  0.976879\n",
       "7  0.014739  1.000000  1.000000"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = pd.DataFrame()  # 创建一个空DataFrame \n",
    "a['阈值'] = list(thres)\n",
    "a['假警报率'] = list(fpr)\n",
    "a['命中率'] = list(tpr)\n",
    "a"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "已知了不同阈值下的假警报率和命中率，可通过matplotlib库可绘制ROC曲线，代码如下："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD4CAYAAAD8Zh1EAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6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dVqTPCdzYfHwTq++MViqZ+VXWv3PbI8AfZsNLwM0R8f5rec3rOdC7dnPqEinS51aP0/gfvsw27HNE3Avsy8y/3MrCNlGR9/lu4O6I+FpEvBQRD2xZdZujSJ9/G/h0RJykcf+F39ya0nrman/fN1ToBhc90rWbU5dI4f5ExKeBSeDnN7WizbdunyNiAPgC8GtbVdAWKPI+D9GYdvk4jU9hfxMR92TmO5tc22Yp0ufHgC9l5n+JiH9M4y5o92Tm4uaX1xNdz6/reYTejzenLtJnIuITwOeAhzNzbotq2ywb9XkXcA/wlYh4g8Zc4+GSHxgt+rP9F5m5kJnHgSkaAV9WRfr8OPA8QGb+LbCdxpdYVVWh3/ercT0Hej/enHrDPjenH/6ARpiXfV4VNuhzZp7LzLHMnMjMCRrHDR7OzKO9Kbcrivxs/zmNA+BExBiNKZhjW1pldxXp8w+B+wEi4sM0An1mS6vcWoeBf9E82+WjwLnM/PE17bHXR4I3OEr8EPA6jaPjn2uue4bGLzQ03vA/BaaB/wfc1euat6DP/wc4DXyr+edwr2ve7D63tf0KJT/LpeD7HMB/BV4D/h54tNc1b0GfDwJfo3EGzLeAT/a65mvs75eBHwMLNEbjjwO/Dvx6y3v8bPPf4++78XPtpf+SVBHX85SLJOkqGOiSVBEGuiRVhIEuSRVhoEtSRRjoklQRBrokVcT/ByLBSh124X/ZAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "plt.plot(fpr, tpr)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "通过如下代码则可以快速求出模型的AUC值："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.9736722483245008\n"
     ]
    }
   ],
   "source": [
    "from sklearn.metrics import roc_auc_score\n",
    "score = roc_auc_score(y_test, y_pred_proba[:,1])\n",
    "print(score)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**4.特征重要性评估**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.        , 0.59810862, 0.14007392, 0.10638659, 0.00456495,\n",
       "       0.15086592])"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.feature_importances_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>特征名称</th>\n",
       "      <th>特征重要性</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>满意度</td>\n",
       "      <td>0.598109</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>工龄</td>\n",
       "      <td>0.150866</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>考核得分</td>\n",
       "      <td>0.140074</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>工程数量</td>\n",
       "      <td>0.106387</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>月工时</td>\n",
       "      <td>0.004565</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>工资</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   特征名称     特征重要性\n",
       "1   满意度  0.598109\n",
       "5    工龄  0.150866\n",
       "2  考核得分  0.140074\n",
       "3  工程数量  0.106387\n",
       "4   月工时  0.004565\n",
       "0    工资  0.000000"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 通过DataFrame进行展示，并根据重要性进行倒序排列\n",
    "features = X.columns  # 获取特征名称\n",
    "importances = model.feature_importances_  # 获取特征重要性\n",
    "\n",
    "# 通过二维表格形式显示\n",
    "importances_df = pd.DataFrame()\n",
    "importances_df['特征名称'] = features\n",
    "importances_df['特征重要性'] = importances\n",
    "importances_df.sort_values('特征重要性', ascending=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**5.2.3 决策树模型可视化呈现及决策树要点理解**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "通过graphviz插件进行决策树可视化，graphviz插件的更详细的使用教程可以查看该文档:https://shimo.im/docs/Dcgw8H6WxgWrc8hq/ "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "可视化文件result.pdf已经保存在代码所在文件夹！\n"
     ]
    }
   ],
   "source": [
    "# 1.如果不用显示中文，那么通过如下代码即可：\n",
    "# !pip3 install pygraphviz\n",
    "from sklearn.tree import export_graphviz\n",
    "import graphviz\n",
    "import os  # 以下这两行是手动进行环境变量配置，防止在本机环境的变量部署失败\n",
    "os.environ['PATH'] = os.pathsep + r'C:\\Program Files (x86)\\Graphviz2.38\\bin'\n",
    "\n",
    "dot_data = export_graphviz(model, out_file=None, class_names=['0', '1'])\n",
    "graph = graphviz.Source(dot_data)\n",
    "\n",
    "graph.render(\"result\")  # 导出成PDF文件\n",
    "print('可视化文件result.pdf已经保存在代码所在文件夹！')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\r\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\r\n",
       " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\r\n",
       "<!-- Generated by graphviz version 2.38.0 (20140413.2041)\r\n",
       " -->\r\n",
       "<!-- Title: Tree Pages: 1 -->\r\n",
       "<svg width=\"1018pt\" height=\"433pt\"\r\n",
       " viewBox=\"0.00 0.00 1018.00 433.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\r\n",
       "<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 429)\">\r\n",
       "<title>Tree</title>\r\n",
       "<polygon fill=\"white\" stroke=\"none\" points=\"-4,4 -4,-429 1014,-429 1014,4 -4,4\"/>\r\n",
       "<!-- 0 -->\r\n",
       "<g id=\"node1\" class=\"node\"><title>0</title>\r\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"567.5,-425 436.5,-425 436.5,-342 567.5,-342 567.5,-425\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"502\" y=\"-409.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">X[1] &lt;= 4.65</text>\r\n",
       "<text text-anchor=\"middle\" x=\"502\" y=\"-394.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">gini = 0.365</text>\r\n",
       "<text text-anchor=\"middle\" x=\"502\" y=\"-379.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">samples = 12000</text>\r\n",
       "<text text-anchor=\"middle\" x=\"502\" y=\"-364.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">value = [9120, 2880]</text>\r\n",
       "<text text-anchor=\"middle\" x=\"502\" y=\"-349.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">class = 0</text>\r\n",
       "</g>\r\n",
       "<!-- 1 -->\r\n",
       "<g id=\"node2\" class=\"node\"><title>1</title>\r\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"470.5,-306 339.5,-306 339.5,-223 470.5,-223 470.5,-306\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"405\" y=\"-290.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">X[3] &lt;= 2.5</text>\r\n",
       "<text text-anchor=\"middle\" x=\"405\" y=\"-275.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">gini = 0.477</text>\r\n",
       "<text text-anchor=\"middle\" x=\"405\" y=\"-260.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">samples = 3367</text>\r\n",
       "<text text-anchor=\"middle\" x=\"405\" y=\"-245.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">value = [1325, 2042]</text>\r\n",
       "<text text-anchor=\"middle\" x=\"405\" y=\"-230.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">class = 1</text>\r\n",
       "</g>\r\n",
       "<!-- 0&#45;&gt;1 -->\r\n",
       "<g id=\"edge1\" class=\"edge\"><title>0&#45;&gt;1</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M468.346,-341.907C460.823,-332.832 452.771,-323.121 445.018,-313.769\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"447.671,-311.485 438.594,-306.021 442.282,-315.953 447.671,-311.485\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"436.268\" y=\"-327.212\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">True</text>\r\n",
       "</g>\r\n",
       "<!-- 8 -->\r\n",
       "<g id=\"node9\" class=\"node\"><title>8</title>\r\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"662.5,-306 537.5,-306 537.5,-223 662.5,-223 662.5,-306\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"600\" y=\"-290.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">X[5] &lt;= 4.5</text>\r\n",
       "<text text-anchor=\"middle\" x=\"600\" y=\"-275.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">gini = 0.175</text>\r\n",
       "<text text-anchor=\"middle\" x=\"600\" y=\"-260.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">samples = 8633</text>\r\n",
       "<text text-anchor=\"middle\" x=\"600\" y=\"-245.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">value = [7795, 838]</text>\r\n",
       "<text text-anchor=\"middle\" x=\"600\" y=\"-230.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">class = 0</text>\r\n",
       "</g>\r\n",
       "<!-- 0&#45;&gt;8 -->\r\n",
       "<g id=\"edge8\" class=\"edge\"><title>0&#45;&gt;8</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M536.001,-341.907C543.602,-332.832 551.736,-323.121 559.569,-313.769\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"562.321,-315.934 566.059,-306.021 556.955,-311.439 562.321,-315.934\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"568.26\" y=\"-327.224\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">False</text>\r\n",
       "</g>\r\n",
       "<!-- 2 -->\r\n",
       "<g id=\"node3\" class=\"node\"><title>2</title>\r\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"247.5,-187 122.5,-187 122.5,-104 247.5,-104 247.5,-187\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"185\" y=\"-171.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">X[2] &lt;= 0.575</text>\r\n",
       "<text text-anchor=\"middle\" x=\"185\" y=\"-156.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">gini = 0.208</text>\r\n",
       "<text text-anchor=\"middle\" x=\"185\" y=\"-141.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">samples = 1396</text>\r\n",
       "<text text-anchor=\"middle\" x=\"185\" y=\"-126.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">value = [165, 1231]</text>\r\n",
       "<text text-anchor=\"middle\" x=\"185\" y=\"-111.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">class = 1</text>\r\n",
       "</g>\r\n",
       "<!-- 1&#45;&gt;2 -->\r\n",
       "<g id=\"edge2\" class=\"edge\"><title>1&#45;&gt;2</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M339.291,-228.555C313.241,-214.701 283.213,-198.731 256.61,-184.583\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"258.202,-181.466 247.73,-179.861 254.915,-187.647 258.202,-181.466\"/>\r\n",
       "</g>\r\n",
       "<!-- 5 -->\r\n",
       "<g id=\"node6\" class=\"node\"><title>5</title>\r\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"467.5,-187 342.5,-187 342.5,-104 467.5,-104 467.5,-187\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"405\" y=\"-171.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">X[1] &lt;= 1.15</text>\r\n",
       "<text text-anchor=\"middle\" x=\"405\" y=\"-156.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">gini = 0.484</text>\r\n",
       "<text text-anchor=\"middle\" x=\"405\" y=\"-141.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">samples = 1971</text>\r\n",
       "<text text-anchor=\"middle\" x=\"405\" y=\"-126.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">value = [1160, 811]</text>\r\n",
       "<text text-anchor=\"middle\" x=\"405\" y=\"-111.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">class = 0</text>\r\n",
       "</g>\r\n",
       "<!-- 1&#45;&gt;5 -->\r\n",
       "<g id=\"edge5\" class=\"edge\"><title>1&#45;&gt;5</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M405,-222.907C405,-214.649 405,-205.864 405,-197.302\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"408.5,-197.021 405,-187.021 401.5,-197.021 408.5,-197.021\"/>\r\n",
       "</g>\r\n",
       "<!-- 3 -->\r\n",
       "<g id=\"node4\" class=\"node\"><title>3</title>\r\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"118,-68 0,-68 0,-0 118,-0 118,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"59\" y=\"-52.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">gini = 0.102</text>\r\n",
       "<text text-anchor=\"middle\" x=\"59\" y=\"-37.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">samples = 1295</text>\r\n",
       "<text text-anchor=\"middle\" x=\"59\" y=\"-22.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">value = [70, 1225]</text>\r\n",
       "<text text-anchor=\"middle\" x=\"59\" y=\"-7.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">class = 1</text>\r\n",
       "</g>\r\n",
       "<!-- 2&#45;&gt;3 -->\r\n",
       "<g id=\"edge3\" class=\"edge\"><title>2&#45;&gt;3</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M138.082,-103.726C127.272,-94.3318 115.785,-84.349 105.014,-74.9883\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"107.161,-72.2174 97.3173,-68.2996 102.57,-77.501 107.161,-72.2174\"/>\r\n",
       "</g>\r\n",
       "<!-- 4 -->\r\n",
       "<g id=\"node5\" class=\"node\"><title>4</title>\r\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"234,-68 136,-68 136,-0 234,-0 234,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"185\" y=\"-52.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">gini = 0.112</text>\r\n",
       "<text text-anchor=\"middle\" x=\"185\" y=\"-37.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">samples = 101</text>\r\n",
       "<text text-anchor=\"middle\" x=\"185\" y=\"-22.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">value = [95, 6]</text>\r\n",
       "<text text-anchor=\"middle\" x=\"185\" y=\"-7.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">class = 0</text>\r\n",
       "</g>\r\n",
       "<!-- 2&#45;&gt;4 -->\r\n",
       "<g id=\"edge4\" class=\"edge\"><title>2&#45;&gt;4</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M185,-103.726C185,-95.5175 185,-86.8595 185,-78.56\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"188.5,-78.2996 185,-68.2996 181.5,-78.2996 188.5,-78.2996\"/>\r\n",
       "</g>\r\n",
       "<!-- 6 -->\r\n",
       "<g id=\"node7\" class=\"node\"><title>6</title>\r\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"356,-68 252,-68 252,-0 356,-0 356,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"304\" y=\"-52.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">gini = 0.0</text>\r\n",
       "<text text-anchor=\"middle\" x=\"304\" y=\"-37.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">samples = 714</text>\r\n",
       "<text text-anchor=\"middle\" x=\"304\" y=\"-22.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">value = [0, 714]</text>\r\n",
       "<text text-anchor=\"middle\" x=\"304\" y=\"-7.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">class = 1</text>\r\n",
       "</g>\r\n",
       "<!-- 5&#45;&gt;6 -->\r\n",
       "<g id=\"edge6\" class=\"edge\"><title>5&#45;&gt;6</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M367.391,-103.726C358.979,-94.6054 350.054,-84.93 341.64,-75.8078\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"344.067,-73.2772 334.715,-68.2996 338.922,-78.0232 344.067,-73.2772\"/>\r\n",
       "</g>\r\n",
       "<!-- 7 -->\r\n",
       "<g id=\"node8\" class=\"node\"><title>7</title>\r\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"492,-68 374,-68 374,-0 492,-0 492,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"433\" y=\"-52.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">gini = 0.142</text>\r\n",
       "<text text-anchor=\"middle\" x=\"433\" y=\"-37.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">samples = 1257</text>\r\n",
       "<text text-anchor=\"middle\" x=\"433\" y=\"-22.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">value = [1160, 97]</text>\r\n",
       "<text text-anchor=\"middle\" x=\"433\" y=\"-7.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">class = 0</text>\r\n",
       "</g>\r\n",
       "<!-- 5&#45;&gt;7 -->\r\n",
       "<g id=\"edge7\" class=\"edge\"><title>5&#45;&gt;7</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M415.426,-103.726C417.572,-95.3351 419.838,-86.4745 422.003,-78.0072\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"425.398,-78.855 424.485,-68.2996 418.617,-77.1208 425.398,-78.855\"/>\r\n",
       "</g>\r\n",
       "<!-- 9 -->\r\n",
       "<g id=\"node10\" class=\"node\"><title>9</title>\r\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"662.5,-187 537.5,-187 537.5,-104 662.5,-104 662.5,-187\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"600\" y=\"-171.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">X[4] &lt;= 290.5</text>\r\n",
       "<text text-anchor=\"middle\" x=\"600\" y=\"-156.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">gini = 0.031</text>\r\n",
       "<text text-anchor=\"middle\" x=\"600\" y=\"-141.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">samples = 7064</text>\r\n",
       "<text text-anchor=\"middle\" x=\"600\" y=\"-126.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">value = [6952, 112]</text>\r\n",
       "<text text-anchor=\"middle\" x=\"600\" y=\"-111.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">class = 0</text>\r\n",
       "</g>\r\n",
       "<!-- 8&#45;&gt;9 -->\r\n",
       "<g id=\"edge9\" class=\"edge\"><title>8&#45;&gt;9</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M600,-222.907C600,-214.649 600,-205.864 600,-197.302\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"603.5,-197.021 600,-187.021 596.5,-197.021 603.5,-197.021\"/>\r\n",
       "</g>\r\n",
       "<!-- 12 -->\r\n",
       "<g id=\"node13\" class=\"node\"><title>12</title>\r\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"877,-187 759,-187 759,-104 877,-104 877,-187\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"818\" y=\"-171.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">X[2] &lt;= 0.805</text>\r\n",
       "<text text-anchor=\"middle\" x=\"818\" y=\"-156.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">gini = 0.497</text>\r\n",
       "<text text-anchor=\"middle\" x=\"818\" y=\"-141.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">samples = 1569</text>\r\n",
       "<text text-anchor=\"middle\" x=\"818\" y=\"-126.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">value = [843, 726]</text>\r\n",
       "<text text-anchor=\"middle\" x=\"818\" y=\"-111.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">class = 0</text>\r\n",
       "</g>\r\n",
       "<!-- 8&#45;&gt;12 -->\r\n",
       "<g id=\"edge12\" class=\"edge\"><title>8&#45;&gt;12</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M662.762,-229.816C690.002,-215.196 721.972,-198.038 749.796,-183.105\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"751.517,-186.153 758.674,-178.34 748.207,-179.985 751.517,-186.153\"/>\r\n",
       "</g>\r\n",
       "<!-- 10 -->\r\n",
       "<g id=\"node11\" class=\"node\"><title>10</title>\r\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"635.5,-68 510.5,-68 510.5,-0 635.5,-0 635.5,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"573\" y=\"-52.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">gini = 0.029</text>\r\n",
       "<text text-anchor=\"middle\" x=\"573\" y=\"-37.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">samples = 7056</text>\r\n",
       "<text text-anchor=\"middle\" x=\"573\" y=\"-22.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">value = [6952, 104]</text>\r\n",
       "<text text-anchor=\"middle\" x=\"573\" y=\"-7.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">class = 0</text>\r\n",
       "</g>\r\n",
       "<!-- 9&#45;&gt;10 -->\r\n",
       "<g id=\"edge10\" class=\"edge\"><title>9&#45;&gt;10</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M589.946,-103.726C587.9,-95.4263 585.74,-86.6671 583.673,-78.2834\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"587.003,-77.1709 581.211,-68.2996 580.207,-78.8467 587.003,-77.1709\"/>\r\n",
       "</g>\r\n",
       "<!-- 11 -->\r\n",
       "<g id=\"node12\" class=\"node\"><title>11</title>\r\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"744.5,-68 653.5,-68 653.5,-0 744.5,-0 744.5,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"699\" y=\"-52.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">gini = 0.0</text>\r\n",
       "<text text-anchor=\"middle\" x=\"699\" y=\"-37.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">samples = 8</text>\r\n",
       "<text text-anchor=\"middle\" x=\"699\" y=\"-22.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">value = [0, 8]</text>\r\n",
       "<text text-anchor=\"middle\" x=\"699\" y=\"-7.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">class = 1</text>\r\n",
       "</g>\r\n",
       "<!-- 9&#45;&gt;11 -->\r\n",
       "<g id=\"edge11\" class=\"edge\"><title>9&#45;&gt;11</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M636.864,-103.726C645.11,-94.6054 653.858,-84.93 662.105,-75.8078\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"664.783,-78.0647 668.894,-68.2996 659.591,-73.3701 664.783,-78.0647\"/>\r\n",
       "</g>\r\n",
       "<!-- 13 -->\r\n",
       "<g id=\"node14\" class=\"node\"><title>13</title>\r\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"873.5,-68 762.5,-68 762.5,-0 873.5,-0 873.5,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"818\" y=\"-52.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">gini = 0.087</text>\r\n",
       "<text text-anchor=\"middle\" x=\"818\" y=\"-37.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">samples = 590</text>\r\n",
       "<text text-anchor=\"middle\" x=\"818\" y=\"-22.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">value = [563, 27]</text>\r\n",
       "<text text-anchor=\"middle\" x=\"818\" y=\"-7.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">class = 0</text>\r\n",
       "</g>\r\n",
       "<!-- 12&#45;&gt;13 -->\r\n",
       "<g id=\"edge13\" class=\"edge\"><title>12&#45;&gt;13</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M818,-103.726C818,-95.5175 818,-86.8595 818,-78.56\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"821.5,-78.2996 818,-68.2996 814.5,-78.2996 821.5,-78.2996\"/>\r\n",
       "</g>\r\n",
       "<!-- 14 -->\r\n",
       "<g id=\"node15\" class=\"node\"><title>14</title>\r\n",
       "<polygon fill=\"none\" stroke=\"black\" points=\"1010,-68 892,-68 892,-0 1010,-0 1010,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"951\" y=\"-52.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">gini = 0.408</text>\r\n",
       "<text text-anchor=\"middle\" x=\"951\" y=\"-37.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">samples = 979</text>\r\n",
       "<text text-anchor=\"middle\" x=\"951\" y=\"-22.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">value = [280, 699]</text>\r\n",
       "<text text-anchor=\"middle\" x=\"951\" y=\"-7.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">class = 1</text>\r\n",
       "</g>\r\n",
       "<!-- 12&#45;&gt;14 -->\r\n",
       "<g id=\"edge14\" class=\"edge\"><title>12&#45;&gt;14</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M867.524,-103.726C879.046,-94.2406 891.296,-84.1551 902.761,-74.7159\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"905.058,-77.3577 910.554,-68.2996 900.609,-71.9536 905.058,-77.3577\"/>\r\n",
       "</g>\r\n",
       "</g>\r\n",
       "</svg>\r\n"
      ],
      "text/plain": [
       "<graphviz.files.Source at 0x24add592908>"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "graph  # 在Jupyter Notebook中可以直接输入变量名查看可视化图片"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\r\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\r\n",
       " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\r\n",
       "<!-- Generated by graphviz version 2.38.0 (20140413.2041)\r\n",
       " -->\r\n",
       "<!-- Title: Tree Pages: 1 -->\r\n",
       "<svg width=\"1018pt\" height=\"433pt\"\r\n",
       " viewBox=\"0.00 0.00 1018.00 433.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\r\n",
       "<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 429)\">\r\n",
       "<title>Tree</title>\r\n",
       "<polygon fill=\"white\" stroke=\"none\" points=\"-4,4 -4,-429 1014,-429 1014,4 -4,4\"/>\r\n",
       "<!-- 0 -->\r\n",
       "<g id=\"node1\" class=\"node\"><title>0</title>\r\n",
       "<polygon fill=\"#eda978\" stroke=\"black\" points=\"568.5,-425 437.5,-425 437.5,-342 568.5,-342 568.5,-425\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"503\" y=\"-409.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">satisfication &lt;= 4.65</text>\r\n",
       "<text text-anchor=\"middle\" x=\"503\" y=\"-394.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">gini = 0.365</text>\r\n",
       "<text text-anchor=\"middle\" x=\"503\" y=\"-379.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">samples = 12000</text>\r\n",
       "<text text-anchor=\"middle\" x=\"503\" y=\"-364.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">value = [9120, 2880]</text>\r\n",
       "<text text-anchor=\"middle\" x=\"503\" y=\"-349.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">class = 0</text>\r\n",
       "</g>\r\n",
       "<!-- 1 -->\r\n",
       "<g id=\"node2\" class=\"node\"><title>1</title>\r\n",
       "<polygon fill=\"#b9ddf6\" stroke=\"black\" points=\"471.5,-306 340.5,-306 340.5,-223 471.5,-223 471.5,-306\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"406\" y=\"-290.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">project_num &lt;= 2.5</text>\r\n",
       "<text text-anchor=\"middle\" x=\"406\" y=\"-275.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">gini = 0.477</text>\r\n",
       "<text text-anchor=\"middle\" x=\"406\" y=\"-260.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">samples = 3367</text>\r\n",
       "<text text-anchor=\"middle\" x=\"406\" y=\"-245.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">value = [1325, 2042]</text>\r\n",
       "<text text-anchor=\"middle\" x=\"406\" y=\"-230.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">class = 1</text>\r\n",
       "</g>\r\n",
       "<!-- 0&#45;&gt;1 -->\r\n",
       "<g id=\"edge1\" class=\"edge\"><title>0&#45;&gt;1</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M469.346,-341.907C461.823,-332.832 453.771,-323.121 446.018,-313.769\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"448.671,-311.485 439.594,-306.021 443.282,-315.953 448.671,-311.485\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"437.268\" y=\"-327.212\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">True</text>\r\n",
       "</g>\r\n",
       "<!-- 8 -->\r\n",
       "<g id=\"node9\" class=\"node\"><title>8</title>\r\n",
       "<polygon fill=\"#e88f4e\" stroke=\"black\" points=\"662.5,-306 537.5,-306 537.5,-223 662.5,-223 662.5,-306\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"600\" y=\"-290.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">year &lt;= 4.5</text>\r\n",
       "<text text-anchor=\"middle\" x=\"600\" y=\"-275.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">gini = 0.175</text>\r\n",
       "<text text-anchor=\"middle\" x=\"600\" y=\"-260.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">samples = 8633</text>\r\n",
       "<text text-anchor=\"middle\" x=\"600\" y=\"-245.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">value = [7795, 838]</text>\r\n",
       "<text text-anchor=\"middle\" x=\"600\" y=\"-230.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">class = 0</text>\r\n",
       "</g>\r\n",
       "<!-- 0&#45;&gt;8 -->\r\n",
       "<g id=\"edge8\" class=\"edge\"><title>0&#45;&gt;8</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M536.654,-341.907C544.177,-332.832 552.229,-323.121 559.982,-313.769\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"562.718,-315.953 566.406,-306.021 557.329,-311.485 562.718,-315.953\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"568.732\" y=\"-327.212\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">False</text>\r\n",
       "</g>\r\n",
       "<!-- 2 -->\r\n",
       "<g id=\"node3\" class=\"node\"><title>2</title>\r\n",
       "<polygon fill=\"#54aae8\" stroke=\"black\" points=\"247.5,-187 122.5,-187 122.5,-104 247.5,-104 247.5,-187\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"185\" y=\"-171.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">score &lt;= 0.575</text>\r\n",
       "<text text-anchor=\"middle\" x=\"185\" y=\"-156.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">gini = 0.208</text>\r\n",
       "<text text-anchor=\"middle\" x=\"185\" y=\"-141.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">samples = 1396</text>\r\n",
       "<text text-anchor=\"middle\" x=\"185\" y=\"-126.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">value = [165, 1231]</text>\r\n",
       "<text text-anchor=\"middle\" x=\"185\" y=\"-111.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">class = 1</text>\r\n",
       "</g>\r\n",
       "<!-- 1&#45;&gt;2 -->\r\n",
       "<g id=\"edge2\" class=\"edge\"><title>1&#45;&gt;2</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M340.291,-228.713C313.999,-214.794 283.634,-198.718 256.767,-184.494\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"258.276,-181.333 247.801,-179.748 255.001,-187.52 258.276,-181.333\"/>\r\n",
       "</g>\r\n",
       "<!-- 5 -->\r\n",
       "<g id=\"node6\" class=\"node\"><title>5</title>\r\n",
       "<polygon fill=\"#f7d9c3\" stroke=\"black\" points=\"471.5,-187 340.5,-187 340.5,-104 471.5,-104 471.5,-187\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"406\" y=\"-171.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">satisfication &lt;= 1.15</text>\r\n",
       "<text text-anchor=\"middle\" x=\"406\" y=\"-156.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">gini = 0.484</text>\r\n",
       "<text text-anchor=\"middle\" x=\"406\" y=\"-141.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">samples = 1971</text>\r\n",
       "<text text-anchor=\"middle\" x=\"406\" y=\"-126.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">value = [1160, 811]</text>\r\n",
       "<text text-anchor=\"middle\" x=\"406\" y=\"-111.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">class = 0</text>\r\n",
       "</g>\r\n",
       "<!-- 1&#45;&gt;5 -->\r\n",
       "<g id=\"edge5\" class=\"edge\"><title>1&#45;&gt;5</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M406,-222.907C406,-214.649 406,-205.864 406,-197.302\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"409.5,-197.021 406,-187.021 402.5,-197.021 409.5,-197.021\"/>\r\n",
       "</g>\r\n",
       "<!-- 3 -->\r\n",
       "<g id=\"node4\" class=\"node\"><title>3</title>\r\n",
       "<polygon fill=\"#44a3e6\" stroke=\"black\" points=\"118,-68 0,-68 0,-0 118,-0 118,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"59\" y=\"-52.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">gini = 0.102</text>\r\n",
       "<text text-anchor=\"middle\" x=\"59\" y=\"-37.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">samples = 1295</text>\r\n",
       "<text text-anchor=\"middle\" x=\"59\" y=\"-22.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">value = [70, 1225]</text>\r\n",
       "<text text-anchor=\"middle\" x=\"59\" y=\"-7.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">class = 1</text>\r\n",
       "</g>\r\n",
       "<!-- 2&#45;&gt;3 -->\r\n",
       "<g id=\"edge3\" class=\"edge\"><title>2&#45;&gt;3</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M138.082,-103.726C127.272,-94.3318 115.785,-84.349 105.014,-74.9883\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"107.161,-72.2174 97.3173,-68.2996 102.57,-77.501 107.161,-72.2174\"/>\r\n",
       "</g>\r\n",
       "<!-- 4 -->\r\n",
       "<g id=\"node5\" class=\"node\"><title>4</title>\r\n",
       "<polygon fill=\"#e78946\" stroke=\"black\" points=\"234,-68 136,-68 136,-0 234,-0 234,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"185\" y=\"-52.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">gini = 0.112</text>\r\n",
       "<text text-anchor=\"middle\" x=\"185\" y=\"-37.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">samples = 101</text>\r\n",
       "<text text-anchor=\"middle\" x=\"185\" y=\"-22.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">value = [95, 6]</text>\r\n",
       "<text text-anchor=\"middle\" x=\"185\" y=\"-7.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">class = 0</text>\r\n",
       "</g>\r\n",
       "<!-- 2&#45;&gt;4 -->\r\n",
       "<g id=\"edge4\" class=\"edge\"><title>2&#45;&gt;4</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M185,-103.726C185,-95.5175 185,-86.8595 185,-78.56\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"188.5,-78.2996 185,-68.2996 181.5,-78.2996 188.5,-78.2996\"/>\r\n",
       "</g>\r\n",
       "<!-- 6 -->\r\n",
       "<g id=\"node7\" class=\"node\"><title>6</title>\r\n",
       "<polygon fill=\"#399de5\" stroke=\"black\" points=\"356,-68 252,-68 252,-0 356,-0 356,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"304\" y=\"-52.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">gini = 0.0</text>\r\n",
       "<text text-anchor=\"middle\" x=\"304\" y=\"-37.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">samples = 714</text>\r\n",
       "<text text-anchor=\"middle\" x=\"304\" y=\"-22.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">value = [0, 714]</text>\r\n",
       "<text text-anchor=\"middle\" x=\"304\" y=\"-7.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">class = 1</text>\r\n",
       "</g>\r\n",
       "<!-- 5&#45;&gt;6 -->\r\n",
       "<g id=\"edge6\" class=\"edge\"><title>5&#45;&gt;6</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M368.019,-103.726C359.523,-94.6054 350.51,-84.93 342.013,-75.8078\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"344.396,-73.2312 335.019,-68.2996 339.274,-78.0025 344.396,-73.2312\"/>\r\n",
       "</g>\r\n",
       "<!-- 7 -->\r\n",
       "<g id=\"node8\" class=\"node\"><title>7</title>\r\n",
       "<polygon fill=\"#e78c4a\" stroke=\"black\" points=\"492,-68 374,-68 374,-0 492,-0 492,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"433\" y=\"-52.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">gini = 0.142</text>\r\n",
       "<text text-anchor=\"middle\" x=\"433\" y=\"-37.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">samples = 1257</text>\r\n",
       "<text text-anchor=\"middle\" x=\"433\" y=\"-22.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">value = [1160, 97]</text>\r\n",
       "<text text-anchor=\"middle\" x=\"433\" y=\"-7.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">class = 0</text>\r\n",
       "</g>\r\n",
       "<!-- 5&#45;&gt;7 -->\r\n",
       "<g id=\"edge7\" class=\"edge\"><title>5&#45;&gt;7</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M416.054,-103.726C418.1,-95.4263 420.26,-86.6671 422.327,-78.2834\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"425.793,-78.8467 424.789,-68.2996 418.997,-77.1709 425.793,-78.8467\"/>\r\n",
       "</g>\r\n",
       "<!-- 9 -->\r\n",
       "<g id=\"node10\" class=\"node\"><title>9</title>\r\n",
       "<polygon fill=\"#e5833c\" stroke=\"black\" points=\"662.5,-187 537.5,-187 537.5,-104 662.5,-104 662.5,-187\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"600\" y=\"-171.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">hours &lt;= 290.5</text>\r\n",
       "<text text-anchor=\"middle\" x=\"600\" y=\"-156.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">gini = 0.031</text>\r\n",
       "<text text-anchor=\"middle\" x=\"600\" y=\"-141.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">samples = 7064</text>\r\n",
       "<text text-anchor=\"middle\" x=\"600\" y=\"-126.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">value = [6952, 112]</text>\r\n",
       "<text text-anchor=\"middle\" x=\"600\" y=\"-111.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">class = 0</text>\r\n",
       "</g>\r\n",
       "<!-- 8&#45;&gt;9 -->\r\n",
       "<g id=\"edge9\" class=\"edge\"><title>8&#45;&gt;9</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M600,-222.907C600,-214.649 600,-205.864 600,-197.302\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"603.5,-197.021 600,-187.021 596.5,-197.021 603.5,-197.021\"/>\r\n",
       "</g>\r\n",
       "<!-- 12 -->\r\n",
       "<g id=\"node13\" class=\"node\"><title>12</title>\r\n",
       "<polygon fill=\"#fbeee4\" stroke=\"black\" points=\"877,-187 759,-187 759,-104 877,-104 877,-187\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"818\" y=\"-171.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">score &lt;= 0.805</text>\r\n",
       "<text text-anchor=\"middle\" x=\"818\" y=\"-156.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">gini = 0.497</text>\r\n",
       "<text text-anchor=\"middle\" x=\"818\" y=\"-141.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">samples = 1569</text>\r\n",
       "<text text-anchor=\"middle\" x=\"818\" y=\"-126.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">value = [843, 726]</text>\r\n",
       "<text text-anchor=\"middle\" x=\"818\" y=\"-111.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">class = 0</text>\r\n",
       "</g>\r\n",
       "<!-- 8&#45;&gt;12 -->\r\n",
       "<g id=\"edge12\" class=\"edge\"><title>8&#45;&gt;12</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M662.762,-229.816C690.002,-215.196 721.972,-198.038 749.796,-183.105\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"751.517,-186.153 758.674,-178.34 748.207,-179.985 751.517,-186.153\"/>\r\n",
       "</g>\r\n",
       "<!-- 10 -->\r\n",
       "<g id=\"node11\" class=\"node\"><title>10</title>\r\n",
       "<polygon fill=\"#e5833c\" stroke=\"black\" points=\"635.5,-68 510.5,-68 510.5,-0 635.5,-0 635.5,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"573\" y=\"-52.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">gini = 0.029</text>\r\n",
       "<text text-anchor=\"middle\" x=\"573\" y=\"-37.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">samples = 7056</text>\r\n",
       "<text text-anchor=\"middle\" x=\"573\" y=\"-22.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">value = [6952, 104]</text>\r\n",
       "<text text-anchor=\"middle\" x=\"573\" y=\"-7.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">class = 0</text>\r\n",
       "</g>\r\n",
       "<!-- 9&#45;&gt;10 -->\r\n",
       "<g id=\"edge10\" class=\"edge\"><title>9&#45;&gt;10</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M589.946,-103.726C587.9,-95.4263 585.74,-86.6671 583.673,-78.2834\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"587.003,-77.1709 581.211,-68.2996 580.207,-78.8467 587.003,-77.1709\"/>\r\n",
       "</g>\r\n",
       "<!-- 11 -->\r\n",
       "<g id=\"node12\" class=\"node\"><title>11</title>\r\n",
       "<polygon fill=\"#399de5\" stroke=\"black\" points=\"744.5,-68 653.5,-68 653.5,-0 744.5,-0 744.5,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"699\" y=\"-52.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">gini = 0.0</text>\r\n",
       "<text text-anchor=\"middle\" x=\"699\" y=\"-37.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">samples = 8</text>\r\n",
       "<text text-anchor=\"middle\" x=\"699\" y=\"-22.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">value = [0, 8]</text>\r\n",
       "<text text-anchor=\"middle\" x=\"699\" y=\"-7.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">class = 1</text>\r\n",
       "</g>\r\n",
       "<!-- 9&#45;&gt;11 -->\r\n",
       "<g id=\"edge11\" class=\"edge\"><title>9&#45;&gt;11</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M636.864,-103.726C645.11,-94.6054 653.858,-84.93 662.105,-75.8078\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"664.783,-78.0647 668.894,-68.2996 659.591,-73.3701 664.783,-78.0647\"/>\r\n",
       "</g>\r\n",
       "<!-- 13 -->\r\n",
       "<g id=\"node14\" class=\"node\"><title>13</title>\r\n",
       "<polygon fill=\"#e68742\" stroke=\"black\" points=\"873.5,-68 762.5,-68 762.5,-0 873.5,-0 873.5,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"818\" y=\"-52.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">gini = 0.087</text>\r\n",
       "<text text-anchor=\"middle\" x=\"818\" y=\"-37.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">samples = 590</text>\r\n",
       "<text text-anchor=\"middle\" x=\"818\" y=\"-22.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">value = [563, 27]</text>\r\n",
       "<text text-anchor=\"middle\" x=\"818\" y=\"-7.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">class = 0</text>\r\n",
       "</g>\r\n",
       "<!-- 12&#45;&gt;13 -->\r\n",
       "<g id=\"edge13\" class=\"edge\"><title>12&#45;&gt;13</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M818,-103.726C818,-95.5175 818,-86.8595 818,-78.56\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"821.5,-78.2996 818,-68.2996 814.5,-78.2996 821.5,-78.2996\"/>\r\n",
       "</g>\r\n",
       "<!-- 14 -->\r\n",
       "<g id=\"node15\" class=\"node\"><title>14</title>\r\n",
       "<polygon fill=\"#88c4ef\" stroke=\"black\" points=\"1010,-68 892,-68 892,-0 1010,-0 1010,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"951\" y=\"-52.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">gini = 0.408</text>\r\n",
       "<text text-anchor=\"middle\" x=\"951\" y=\"-37.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">samples = 979</text>\r\n",
       "<text text-anchor=\"middle\" x=\"951\" y=\"-22.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">value = [280, 699]</text>\r\n",
       "<text text-anchor=\"middle\" x=\"951\" y=\"-7.8\" font-family=\"Times New Roman,serif\" font-size=\"14.00\">class = 1</text>\r\n",
       "</g>\r\n",
       "<!-- 12&#45;&gt;14 -->\r\n",
       "<g id=\"edge14\" class=\"edge\"><title>12&#45;&gt;14</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M867.524,-103.726C879.046,-94.2406 891.296,-84.1551 902.761,-74.7159\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"905.058,-77.3577 910.554,-68.2996 900.609,-71.9536 905.058,-77.3577\"/>\r\n",
       "</g>\r\n",
       "</g>\r\n",
       "</svg>\r\n"
      ],
      "text/plain": [
       "<graphviz.files.Source at 0x24aee250b70>"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 添加名称（feature_names）和填充颜色（filled=True）\n",
    "dot_data = export_graphviz(model, out_file=None, feature_names=['income', 'satisfication', 'score', 'project_num', 'hours', 'year'], class_names=['0', '1'], filled=True)  \n",
    "graph = graphviz.Source(dot_data)\n",
    "\n",
    "graph"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "决策树模型.png已经保存在代码所在文件夹！\n",
      "决策树模型.pdf已经保存在代码所在文件夹！\n"
     ]
    }
   ],
   "source": [
    "# 2.如果想显示中文，需要使用如下代码\n",
    "from sklearn.tree import export_graphviz\n",
    "import graphviz\n",
    "import os  # 以下这两行是手动进行环境变量配置，防止在本机环境的变量部署失败\n",
    "os.environ['PATH'] = os.pathsep + r'C:\\Program Files (x86)\\Graphviz2.38\\bin'\n",
    "\n",
    "# 生成dot_data\n",
    "dot_data = export_graphviz(model, out_file=None, feature_names=X_train.columns, class_names=['不离职', '离职'], rounded=True, filled=True)\n",
    "\n",
    "# 将生成的dot_data内容导入到txt文件中\n",
    "f = open('dot_data.txt', 'w')\n",
    "f.write(dot_data)\n",
    "f.close()\n",
    "\n",
    "# 修改字体设置，避免中文乱码！\n",
    "import re\n",
    "f_old = open('dot_data.txt', 'r')\n",
    "f_new = open('dot_data_new.txt', 'w', encoding='utf-8')\n",
    "for line in f_old:\n",
    "    if 'fontname' in line:\n",
    "        font_re = 'fontname=(.*?)]'\n",
    "        old_font = re.findall(font_re, line)[0]\n",
    "        line = line.replace(old_font, 'SimHei')\n",
    "    f_new.write(line)\n",
    "f_old.close()\n",
    "f_new.close()\n",
    "\n",
    "# 以PNG的图片形式存储生成的可视化文件\n",
    "os.system('dot -Tpng dot_data_new.txt -o 决策树模型.png')  \n",
    "print('决策树模型.png已经保存在代码所在文件夹！')\n",
    "\n",
    "# 以PDF的形式存储生成的可视化文件\n",
    "os.system('dot -Tpdf dot_data_new.txt -o 决策树模型.pdf')  \n",
    "print('决策树模型.pdf已经保存在代码所在文件夹！')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "此时可以在代码所在文件夹中查看生成的可视化文件"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
